class Solution
{
public:
    int wateringPlants(vector<int> &plants, int capacity)
    {
        int n = plants.size();
        int result = n;
        int cur = capacity;
        for (int i = 0; i < n; ++i)
        {
            if (cur >= plants[i])
            {
                cur -= plants[i];
            }
            else
            {
                cur = capacity - plants[i];
                result += 2 * i;
            }
        }
        return result;
    }
};